package com.zlm.user.emp.controller;

import com.zlm.common.base.BaseController;
import com.zlm.common.base.PageEntity;
import com.zlm.common.constants.CodeConstants;
import com.zlm.common.dto.JsonResultDto;
import com.zlm.common.dto.userEmp.PositionCollectParamsDto;
import com.zlm.user.emp.service.EmpPostCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 职位收藏controller
 * @Author: duyufu
 * @Date: 2019/4/30 15:39
 */
@RestController
@RequestMapping(value = "/empPostCollect")
public class EmpPostCollectController extends BaseController {

    @Autowired
    private EmpPostCollectService empPostCollectService;

    /**
     * 收藏/取消收藏职位
     * @param operationCode
     * @param pracId
     * @param empId
     * @return
     */
    @GetMapping("/saveEmpPostCollect")
    public JsonResultDto saveEmpPostCollect(Integer operationCode, Integer pracId, Integer empId) {
        try {
            String result = empPostCollectService.saveEmpPostCollect(operationCode,pracId,empId);
            if (CodeConstants.CODE_SUCCESS.equals(result)) {
                return success();
            }else {
                return fail(result);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return fail(CodeConstants.CODE_BUSY);
        }
    }

    /**
     * 查询用户职位收藏列表
     * @param positionCollectParamsDto
     * @return
     */
    @PostMapping("/queryEmpPostCollect")
    public JsonResultDto queryEmpPostCollect(@RequestBody PositionCollectParamsDto positionCollectParamsDto) {
        try {
            PageEntity page = empPostCollectService.queryEmpPostCollect(positionCollectParamsDto.getEmpId(),
                    positionCollectParamsDto.getPageSize(),positionCollectParamsDto.getPageNumber());
            return success(page);
        } catch (Exception e) {
            e.printStackTrace();
            return fail(CodeConstants.CODE_BUSY);
        }
    }

}
